package org.ala.tiktools.sharddb.mybatis.interceptor;

import org.ala.tiktools.sharddb.db.ThreadLocalLookupKey;
import org.ala.tiktools.sharddb.mybatis.router.ShardInfo;

/**
 * 分库分表信息追加进线程环境
 *
 * @author ala
 * @date 2025-02-20 15:09
 */
public class ShardInfoThreadLocal {


    /**
     *  分库分表信息
     */
    protected static ThreadLocal<ShardInfo> val = new ThreadLocal<>();

    public static void setShardInfo(ShardInfo info) {
        val.set(info);
        ThreadLocalLookupKey.setLookup(info.getShardDB());
    }
    public static ShardInfo getShardInfo() {return val.get();}
    public static void clearShardInnfo() {
        val.remove();
        ThreadLocalLookupKey.clear();
    }
}
